/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef _InputSystem_H_
#define _InputSystem_H_

#include "Ogre.h"
#include <OIS/OIS.h>

namespace Fish3D
{
	class InputSystem
		: public OIS::KeyListener, public OIS::MouseListener
	{
	protected:
		Ogre::RenderWindow *_win;
		OIS::InputManager *inputManager;
		OIS::Mouse  *_mouse;
		OIS::Keyboard *_keyboard;

		std::map<std::string, OIS::KeyListener*> keyListeners;
		std::map<std::string, OIS::MouseListener*> mouseListeners;

		InputSystem(void);
	public:
		~InputSystem(void);
		inline OIS::Mouse* getMouse()
		{
			return _mouse;
		}

		inline OIS::Keyboard* getKeyboard()
		{
			return _keyboard;
		}

	protected:
		bool keyPressed( const OIS::KeyEvent &e );
		bool keyReleased( const OIS::KeyEvent &e );

		bool mouseMoved( const OIS::MouseEvent &e );
		bool mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id );
		bool mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id );
	public:
		static InputSystem& getSingleton()
		{
			static InputSystem sys;
			return sys;
		}
		void init(Ogre::RenderWindow* win);
		void capture();
		void setWindowExtents(int width,int height);

		void addKeyListener( OIS::KeyListener *keyListener, const std::string& instanceName );
		void addMouseListener( OIS::MouseListener *mouseListener, const std::string& instanceName );

		void removeKeyListener( const std::string& instanceName );
		void removeMouseListener( const std::string& instanceName );
	};
}
#endif
